$(function(){
	var count=document.getElementById("count").value;
	var userGrid = $("#transfer");
	var i=0;
	//初始化
	userGrid.datagrid({
		url:'student/transferList',
		fit:true,
		border :false,
		fitColumns:true,
		rownumbers:true,
		emptyMsg:"<img src='public/images/ty.png'/>",
		pagination : true,// 是否显示分页栏
		columns : [ [ {
			field : 'frontEmp',
			title : '移交人',
			align : 'center',
			width : 90,
			formatter: function (value, rec) {
		         return rec.frontEmp.name;
		     }
		}, {
			field : 'student',
			title : '学生',
			align : 'center',
			width : 90,
			formatter: function (value, rec) {
		         return rec.student.name;
		     }
		}, {
			field : 'afterEmp',
			title : '接收人',
			align : 'center',
			width : 90,
			formatter: function (value, rec) {
		         return rec.afterEmp.name;
		     }
		}, {
			field : 'state',
			title : '状态',
			align : 'center',
			width : 90,
			formatter : function(value, row, index) {
				var bts = [];
				if(value=="已拒绝"){
					bts.push('<div style="margin:0 auto;color:white;border-radius:15px;width:60px;height:20px;line-height:20px;background-color:#FF6C45" data-id="' + row.id + '" data-index="'
							+ index + '" class="ctr py">'+value+'</div>');
				}else if(value=="已同意"){
				bts.push('<div style="margin:0 auto;color:white;border-radius:15px;width:60px;height:20px;line-height:20px;background-color:#66CC66" data-id="' + row.id + '" data-index="'
						+ index + '" class="ctr py">'+value+'</div>');
				}else if(value=="移交中"){
					bts.push('<div style="margin:0 auto;color:white;border-radius:15px;width:60px;height:20px;line-height:20px;background-color:#57C8F2" data-id="' + row.id + '" data-index="'
							+ index + '" class="ctr py">'+value+'</div>');
					}
				return bts.join('');
			}
		} , {
			field : 'reason',
			title : '移交原因',
			align : 'center',
			width : 90
		}, {
			field : 'transferTime',
			title : '移交时间',
			align : 'center',
			width : 90,
			formatter : function(val){
				var newTime = new Date(val);
				var year = newTime.getFullYear();  //获取年
		        var month = newTime.getMonth() + 1;    //获取月
		        var day = newTime.getDate(); //获取日
		        var hours = newTime.getHours(); 
		        var minutes = newTime.getMinutes();
		        var time = year + "-" + month + "-" + day + "" + " " + hours + ":" + minutes;
				return time;
			}
		} ] ],
		toolbar:[
		     {
		    	 iconCls:'icon-tip',
		    	 text:"我的消息"+"<div id='xx' style='float:right;margin-top:2px;border-radius:10px;line-height:14px;width:14px;height:14px;color:white;background-color:#FF0000'>"+count+"</div>",
		    	 handler:function(){
		    		 massageForm();
		    	 }
		     }
		         ]
	});
	if(count>0){
		document.getElementById("xx").style.display="visible";
	}else{
		document.getElementById("xx").style.display="none";
	}
	var name = $("#stuName");
	var frontName = $("#frontName");
	var afterName = $("#afterName");
	//检索按钮时间
	$("#transferSearch").on("click",function(){
		userGrid.datagrid("load",{
			student:name.val(),
			frontEmp:frontName.val(),
			afterEmp:afterName.val()
		});
	});
	var form = $("#transferSearchForm");

	$("#transferReset").on('click', function() {
		form.form('clear');
		// 清除查询参数
		userGrid.datagrid("load", {});
	});
	function a(){
		alert(123);	
	}
	
	function massageForm(){
		// 创建窗口
		var dialog = $("<div/>").dialog({
			href : 'student/transfer_massage',
			title:"我的信息",
			height:380,
			width:790,
			modal : true,
			onClose : function() {
				var tabs = $("#tabs");
				var tab = $("#tabs").tabs('getSelected');
				tab.panel('refresh');
				// 窗口关闭的同时销毁此窗口
				$(this).dialog("destroy");
				
			}
		});
	}
});